import {createStore, applyMiddleware} from 'redux';// 让dispath 也可以异步触发
import rootReducer from '../reducer/index';
import thunk from 'redux-thunk'; // 让dispath 从只接受对象 到 也可以接受函数

const createStoreWidthMiddleware = applyMiddleware(thunk)(createStore);

export default function configureStore(initialState){
  const store = createStoreWidthMiddleware(rootReducer, initialState);

  if(module.hot) {
    module.hot.accept('../reducer', () => {
      store.replaceReducer(rootReducer)
    })
  }

  return store;
}
